//支付方式选择切换
$('.select-delivery li').each(function(index){
	$(this).find('h4').on('tap',function(){
		$('.select-delivery li').removeClass('active');
		$('.select-delivery li').eq(index).addClass('active');

		if(index==0){
			pay_mtd="CCARD";
		}else if(index==1){
			pay_mtd="CASH";
		}else if(index==2){
			pay_mtd="CHEQUE";
		}
	})
})


//是否收到电子发票
$('.agree-protocol').on('tap',function(){
	if($(this).hasClass("active")){
		rec_e_inv_ind="N";
		$(this).removeClass('active');
	}else{
		rec_e_inv_ind="Y";
		$(this).addClass('active');
	}
})

//优惠列表的显示隐藏
$('.coupon h4').on('tap',function(){
	var $listBox=$('.coupon .list');
	var $img=$('.coupon h4 span img');
	if($listBox.css('display')=="none"){
		$listBox.slideDown();
		$img.attr('src',MPJ.base+'/resources/images/icon/delivery-jt-up.png');
	}else{
		$listBox.slideUp();
		$img.attr('src',MPJ.base+'/resources/images/icon/delivery-jt-down.png');
	}
})

//input-btn 验证promotion code是否存在
$('.input-btn button').on('tap',function(){
	var pcode=$('#pcode').val();
	var arr={
		hf_s_id:"WD11",
		hf_srv_id:"Av_jcoupon_code",
		hs_action_id:"save",
		hs_add_coupon_code:pcode,
		hf_locale_id:"en",
	};
	getAjaxRequest(arr,function(result) {
		console.log(result);
		if (result.bs_result != BS_RESULT.OK) {
			dialog('Message', result.bs_message, 3);
			var $dialog = $('#dialog');
			$dialog.show();
			$dialog.find('.comfirmBtn').one('click', function() {
				$dialog.hide();
				$dialog.remove();
				$('#pcode').val('');
			});
		}
	})
})

$('.confirmBtn .mui-btn').on('tap',function(){
	var hs_cc_key = $('#selet-card option:selected').val() == undefined ? "" : $('#selet-card option:selected').val();
	var url = MPJ.apiUrl+'?hf_s_id=WD11&hf_srv_id=Av_jcheckout&hs_action_id=next&hs_scn_id=&hs_cus_dft_cmt=&hs_rec_e_inv_ind='+rec_e_inv_ind+'&hs_cont_bef_del='+cont_bef_del+'&hs_order_cmt='+order_cmt+'&hs_octopus_no='+$('#pNumber').val()+'&hs_hamper_msg='+hamper_msg+'&hs_pay_mtd='+pay_mtd+'&hs_del_win_per='+del_win_per+'&hs_del_date='+del_date+'&hs_cont_bef_del_phone='+$('.hasLogin #h_phone').val()+'&hs_mobile_ind=Y';
	url+='&hs_cc_key='+ hs_cc_key +'&hs_csc='+$('#code').val();
	$('.coupon .list .item').each(function(){
		var $this=$(this);
		var $ramdom_now=$this.find('a.mui-btn');
		if($ramdom_now.hasClass('active')){
			url+='&hvs_add_coupon_type='+$this.data('type')+'&hvs_add_coupon_id='+$this.data('id');
		}
	});
	getAjaxRequest({},function(result) {
		console.log(result)
		if (result.bs_result==BS_RESULT.OK){
			location.href=MPJ.base+"/pages/order/confirm-summary.jsp";
		}else{
			dialog('Message', result.bs_message, 1);
			var $dialog = $('#dialog');
			$dialog.show();
			$dialog.find('.comfirmBtn').one('click', function() {
				$dialog.hide();
				$dialog.remove();
			});

		}
	},url)
})



